#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/*
 *一水分子的质量大约为3.0e-23g,一夸脱水大约有950克，编写一程序，要求从终端输入水的夸脱数，然后显示这么多夸脱水中包含有大概多少水分子
 * */
#define WATER_KT 950
#define   WATER 3.0E-23
static void test1(void)
{
	printf("========\n");
	printf("请输入水的夸脱数:\n");
	float ktNum;
	float waterNum;
	int ret;
	ret = scanf("%f",&ktNum);
	if (ktNum < 0)
	{
		fprintf(stderr,"input err\n");
		exit(1);
	}
	if (ret = 1)
	{
		waterNum = ktNum * WATER_KT / WATER;
		printf("waterNum = %.2e\n",waterNum);

	}else
	{
		printf("Enter error!\n");
	}
	

	return;
}



/*
 *从终端输入三角形的三边长，求面积
 *s = 1/2*(a+b+c);
 *area = sqrt(s*(s-a)*(s-b)*(s-c));
 * */
static void test2(void)
{
	printf("==========\n");
	float a,b,c,s,area;
	int ret;
	printf("输入三角形的三边:\n");
	ret = scanf("%f%f%f",&a,&b,&c);
	if (ret = 3)
	{
		if (a + b > c && a + c > b && b + c >a)
		{
			s= 1.0 / 2.0*(a + b + c);	//原先 1/2 = 0 
			area = sqrt(s*(s-a)*(s-b)*(s-c));	
			printf("area = %f\n",area);


			return;

			/*
 			*编译:gcc exec.c -lm
			*   man sqrt中提示加上 -lm
			*
			*
			*也可以用makefile
			*makefile中加上 CFLAGS += -lm
			*再make exec
 			* */
		}else
		{
			fprintf(stderr,"EINVAL\n");//宏
			exit(1);
		}
	}
	else
	{
		printf("enter error\n");
		exit(1);
	}

}

/*
 *从终端输入a,b,c的值求方程的根
 *b*b -4*a*c >0
 * x1 = (-b+sqrt(b*b-4ac))/2a
 * x2 = (-b-sqrt(b*b-4ac))/2a
 * */

void test3(void)
{
	float a,b,c,x1,x2;
	int ret;
	printf("输入a,b,c的值:\n");
	ret = scanf("%f%f%f",&a,&b,&c);
	if (ret = 3)
	{
		if(b*b-4*a*c >= 0)
		{	
			float temp,q,p;
			temp = sqrt(b*b-4*a*c);
			q = temp / 2 * a;
			p = (-b)/ 2 * a;
			x1 = q + p;
			x2 = q - p;
			printf("x1 = %f\n x2 = %f\n",x1,x2);
		}else
		{
			printf("没有实数根\n");
			return;
		}
	}else
	{
		fprintf(stderr,"EINVAL\n");
		exit(1);	
	}



}



int main(void)
{


//	test1();
//	test2();

	test3();










	exit(0);
}
